﻿Imports EShop.VBClass
Partial Class sqlconfig
    Inherits System.Web.UI.Page



    Dim sqlConfig As String = "sqlconfig.dat"

    Private Sub loadConfig()
        Dim fPath As String = Server.MapPath(sqlConfig)
        If IO.File.Exists(fPath) Then
            Dim strConfigs As String = IO.File.ReadAllText(fPath)

            If strConfigs.Trim <> "" Then
                strConfigs = DecodeAccString(strConfigs, "zyukeys")
                Dim configs() As String = strConfigs.Split(vbCrLf)
                If configs.Length < 3 Then
                    Me.Label_tip5.CssClass = "red"
                    Me.Label_tip5.Text = "注意：数据库配制信息错误，为保证数据正常访问，请重新配制！"
                    Exit Sub
                End If
                Me.TextBox_ServerIP.Text = dValue(configs(0), "")
                Me.TextBox_dbName.Text = dValue(configs(1), "")
                Me.TextBox_UID.Text = dValue(configs(2), "")
                ' Me.TextBox_PWD.Text = configs(3)
            Else
                Me.Label_tip5.CssClass = "red"
                Me.Label_tip5.Text = "注意：数据库配制信息为空，为保证数据正常访问，请重新配制！"
            End If
        Else
            Me.Label_tip5.CssClass = "red"
            Me.Label_tip5.Text = "错误：配制文件不存在，为保证数据正常访问，请配制！"
        End If
    End Sub

    Private Sub saveConfig()
        Try
            Dim fPath As String = Server.MapPath(sqlConfig)
            Dim ServerIP As String = Me.TextBox_ServerIP.Text.Trim
            Dim dbName As String = Me.TextBox_dbName.Text.Trim
            Dim UID As String = Me.TextBox_UID.Text.Trim
            Dim PWD As String = Me.TextBox_PWD.Text.Trim
            Dim PWD0 As String = Me.TextBox_PWD0.Text.Trim

            Dim configB As New StringBuilder
            configB.AppendLine(ServerIP)
            configB.AppendLine(dbName)
            configB.AppendLine(UID)
            configB.AppendLine(PWD)
            'configB.AppendLine(PWD0)
            Dim strConfigs As String = configB.ToString
            strConfigs = EncodeAccString(strConfigs, "zyukeys")
            IO.File.WriteAllText(fPath, strConfigs, System.Text.Encoding.Default)
            Me.Label_tip5.CssClass = "green"
            Me.Label_tip5.Text = "SQL Server 配制成功"
        Catch ex As Exception
            Me.Label_tip5.CssClass = "red"
            Me.Label_tip5.Text = "错误:" & ex.Message
        End Try

    End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            loadConfig()
        End If

    End Sub


    Protected Sub Button_save_Click(sender As Object, e As EventArgs) Handles Button_save.Click
        saveConfig()
        ' loadConfig()
    End Sub
End Class
